package com.wb.mas.ui.success;

import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.wb.mas.data.DemoRepository;
import com.wb.mas.ui.base.viewmodel.ToolbarViewModel;
import com.wb.mas.ui.main.MainActivity;
import com.wb.mas.ui.order.OrderActivity;

import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * Copyright (C) 2018,
 * SuccessViewModel
 * <p>
 * Description
 *
 * @author yue
 * @version 1.0
 * <p>
 * Ver 1.0, 2019-05-23, yue, Create file
 */
public class SuccessViewModel extends ToolbarViewModel {

    public int type;

    public SuccessViewModel(@NonNull Application application, DemoRepository model) {
        super(application, model);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        setRightIconVisible(View.GONE);
    }

    public BindingCommand commitClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (type == SuccessActivity.TYPE_AUTH) {
                backJump();
            } else {
                Bundle bundle = new Bundle();
                bundle.putInt("type", OrderActivity.ORDER_BORROW);
                startActivity(OrderActivity.class, bundle);
                finish();
            }

        }

    });

    @Override
    protected void backOnClick() {
        backJump();
    }


    public void backJump() {
        startActivity(MainActivity.class);
        finish();
    }

}
